<?php
namespace Home\Controller;

// use \Think\Controller;

class GirlController extends HomeController
{
	public function girl()
	{
		      //初始化 
        $curl = curl_init();

        //CURL配置
        //APIKEY的配置 
		$h = ['apikey:5b13b871cbfea93d65ad87cf64a8d3e9'];
		//添加apikey到header头当中
		curl_setopt($curl, CURLOPT_HTTPHEADER, $h);
        //设置CURL的URL选项
        curl_setopt($curl, CURLOPT_URL, 'http://apis.baidu.com/txapi/mvtp/meinv?num=30');

        //将curl_exec()获取的信息 以文件流的形式返回,而不是直接输出.
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

        //设定 为不验证证书SSL和host
        // CURLOPT_SSL_VERIFYHOST  / CURLOPT_SSL_VERIFYPEER
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

        //curl执行
        $data = curl_exec($curl);
        // var_dump($data);//得到结果 为JSON字串

        //关闭curl
        curl_close($curl);

      //处理JSON数据
      $jsonObj = json_decode($data);
      // var_dump($jsonObj);
      //提取文章信息
      $newslist = $jsonObj->newslist;
      // var_dump($newslist);exit;
      $this->assign('list',$newslist);
      $this->display();
	}
}